
#ifndef WRITE_SOLIDWORKSPROCESS_H
#define WRITE_SOLIDWORKSPROCESS_H

#include <string>
#include "datakit.h"
#include <memory>
#include <map>
#include "WriterBase.hpp"
#include "WriteProcess.hpp"

namespace AMCAX::Exchange
{
    class SolidworksWriteProcess : public WriteProcessBase
    {
    public:
        explicit SolidworksWriteProcess(Dtk_string inputFile, std::unique_ptr<WriterBase> writer);
        ~SolidworksWriteProcess() override = default;

        // write through assemblies
        Dtk_ErrorStatus WriteDocument(Dtk_MainDocPtr inDocument, const std::string& outputFile) override;
        Dtk_ErrorStatus WriteComponent(Dtk_ComponentPtr inComponent, const Dtk_transfo& inMatrix, bool bCreateFile = true) override;
        Dtk_ErrorStatus WriteInstance(Dtk_ComponentPtr inComponent) override;
        Dtk_ErrorStatus WritePrototype(Dtk_ComponentPtr inComponent, const Dtk_transfo& inMatrix, Dtk_ID& outPrototypeId) override;

    private:
        Dtk_ErrorStatus BuildPartAssemblyRelationships(const std::string& outputFile);

    private:
        Dtk_tab<Dtk_ID> ComponentProcessed;
        // Assembly prototype id and name map. For buliding the assemblies.
        std::map<Dtk_ID, Dtk_string> m_asseblyIdAndNameMap;
        // Assembly prototype id and instance prototype name and it's transformation pair table map.
        std::unordered_map<Dtk_ID, std::vector<InstanceInfo>> m_assemblyPartsInfoMap;
        std::unordered_map<Dtk_ID, std::vector<Dtk_MetaDataPtr>> m_assemblyMetaDataMap;
    };
}

#endif